#include"processBar.h"
#include<unistd.h>
#include<string.h>

const char* lable="|/-\\";
char bar[NUM];

#define GREEN "\033[0;32;32m"
#define NONE "\033[m"
#define RED  "\033[41m"

void processBar(int rate)
{
	if(rate < 0 || rate > 100) return;

	int len = strlen(lable);
	printf("\033[47m\033[30m\033[1m[%-100s][%d%%][%c]\r\033[0m",bar,rate,lable[rate%len]);
	fflush(stdout);
	bar[rate++] = BODY;
 	if(rate < 100 ) bar[rate] = HEAD;
}

void initBar()
{
	memset(bar,'\0',sizeof(bar));
}

//void processBar(int speed)
//{
//	char bar[NUM];
//	memset(bar,'\0',sizeof(bar));
//	int count = 0;
//	int len = strlen(lable);
//	while(count <= TOP)
//	{
//		printf("[%-100s][%d%%][%c]\r",bar,count,lable[count%len]);
//		fflush(stdout);
//		bar[count++] = BODY;
//	 	if(count < 100 ) bar[count] = HEAD;
//		usleep(speed);
//	}
//	printf("\n");
//}
